//
//  JSMStrategyShowImageViewController.m
//  TakeYouTourTogether
//
//  Created by king on 15/12/7.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMStrategyShowImageViewController.h"
#import "JSMImageShowView.h"
@interface JSMStrategyShowImageViewController ()

@end

@implementation JSMStrategyShowImageViewController

- (id)initWithSourceData:(NSMutableArray *)data withIndex:(NSInteger)index {
    self = [super init];
    if (self) {
//        [self init];
        _data = data;
        _index = index;
    }
    return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //设置导航栏为半透明
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:TRANSPARENT_BACK_IMAGE] forBarMetrics:UIBarMetricsDefault];
    // 隐藏导航栏
    self.navigationController.navigationBarHidden = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.view addGestureRecognizer:tap];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_main@2x.png"]];
    self.view.backgroundColor = [UIColor blackColor];
    // 添加导航栏退回按钮
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:RETURN_IMAGE] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.navigationItem.leftBarButtonItem = backItem;
    [self creatImgShow];
    // Do any additional setup after loading the view.
}

// 初始化视图
- (void)creatImgShow {
    JSMImageShowView *imgShowView = [[JSMImageShowView alloc]
                                           initWithFrame:self.view.frame
                                           withSourceData:_data
                                           withIndex:_index];
    // 解决谦让
    [imgShowView requireDoubleGestureRecognizer:[[self.view gestureRecognizers] lastObject]];
    [self.view addSubview:imgShowView];
}

#pragma mark -UIGestureReconginzer
- (void)tapAction:(UITapGestureRecognizer *)tap {
    // 隐藏导航栏
    [UIView animateWithDuration:0.3 animations:^{
        self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
    }];
}
#pragma mark -NavAction
- (void)backAction{
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Method didReceiveMemoryWarning
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
